/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on Jun 5, 2011, 3:21:59 PM
 */
package dynamicdiscountsystem;

import java.awt.Container;
import java.awt.LayoutManager;
import java.beans.PropertyVetoException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JOptionPane;

/**
 *
 * @author atilla1991
 */
public class MainFrame extends javax.swing.JFrame {

    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        closeMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        definitionMenu = new javax.swing.JMenu();
        discountFormsMenu = new javax.swing.JMenu();
        individualDiscountMenuItem = new javax.swing.JMenuItem();
        sumDiscountMenuItem = new javax.swing.JMenuItem();
        numberDiscountMenuItem = new javax.swing.JMenuItem();
        usersDefinitionMenuItem = new javax.swing.JMenuItem();
        operationMenu = new javax.swing.JMenu();
        productInputMenuItem = new javax.swing.JMenuItem();
        productSaleMenuItem = new javax.swing.JMenuItem();
        discountApplicationMenuItem = new javax.swing.JMenuItem();
        ReportMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Dinamik Endirim Sistemi");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        fileMenu.setText("Fayl");

        closeMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK));
        closeMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dynamicdiscountsystem/resources/close.png"))); // NOI18N
        closeMenuItem.setText("Bağla");
        closeMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(closeMenuItem);

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        exitMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dynamicdiscountsystem/resources/exit.png"))); // NOI18N
        exitMenuItem.setText("Çıxış");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        definitionMenu.setText("Tanımlar");

        discountFormsMenu.setText("Endirim Formaları");

        individualDiscountMenuItem.setText("1. Fərdi  Endirimlər");
        individualDiscountMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                individualDiscountMenuItemActionPerformed(evt);
            }
        });
        discountFormsMenu.add(individualDiscountMenuItem);

        sumDiscountMenuItem.setText("2. Məbləğ Endirimi");
        sumDiscountMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sumDiscountMenuItemActionPerformed(evt);
            }
        });
        discountFormsMenu.add(sumDiscountMenuItem);

        numberDiscountMenuItem.setText("3. N al M ödə Endirimi");
        numberDiscountMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numberDiscountMenuItemActionPerformed(evt);
            }
        });
        discountFormsMenu.add(numberDiscountMenuItem);

        definitionMenu.add(discountFormsMenu);

        usersDefinitionMenuItem.setText("İstifadəçilər");
        usersDefinitionMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                usersDefinitionMenuItemActionPerformed(evt);
            }
        });
        definitionMenu.add(usersDefinitionMenuItem);

        menuBar.add(definitionMenu);

        operationMenu.setText("Əməliyyatlar");

        productInputMenuItem.setText("Mal Girişi");
        productInputMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                productInputMenuItemActionPerformed1(evt);
            }
        });
        operationMenu.add(productInputMenuItem);

        productSaleMenuItem.setText("Mal Satışı");
        productSaleMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                productSaleMenuItemActionPerformed(evt);
            }
        });
        operationMenu.add(productSaleMenuItem);

        discountApplicationMenuItem.setText("Endirimlərin Tətbiqi");
        discountApplicationMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                discountApplicationMenuItemActionPerformed(evt);
            }
        });
        operationMenu.add(discountApplicationMenuItem);

        ReportMenuItem.setText("Hesabat");
        ReportMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReportMenuItemActionPerformed(evt);
            }
        });
        operationMenu.add(ReportMenuItem);

        menuBar.add(operationMenu);

        helpMenu.setText("Kömək");

        aboutMenuItem.setText("Haqqında");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 279, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    JDesktopPane desktop = new JDesktopPane();

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void productInputMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_productInputMenuItemActionPerformed

        ProductInput productInput = new ProductInput();
        desktop.add(productInput);
        productInput.setClosable(true);
        productInput.setFocusable(true);
        productInput.setMaximizable(true);
        productInput.setIconifiable(true);
        desktop.getDesktopManager().maximizeFrame(productInput);
        productInput.setVisible(true);
    }//GEN-LAST:event_productInputMenuItemActionPerformed

    private void productInputMenuItemActionPerformed1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_productInputMenuItemActionPerformed1

        ProductInput frame = new ProductInput();
        frame.setClosable(true);
        frame.setFocusable(true);
        frame.setMaximizable(true);
        frame.setIconifiable(true);
        desktop.add(frame);
        desktop.getDesktopManager().maximizeFrame(frame);
        frame.setVisible(true);
    }//GEN-LAST:event_productInputMenuItemActionPerformed1

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated

        String configFile = "src\\dynamicdiscountsystem\\resources\\ActiveUser.properties";
        Properties config = new Properties();
        String userType = null;
        String usName = null;
        try {

            config.load(new FileReader(configFile));
            userType = config.getProperty("userType");
            usName = config.getProperty("userName");

            if (userType.compareTo("administrator") != 0) {
                usersDefinitionMenuItem.setVisible(false);
                discountFormsMenu.setVisible(false);
            }
        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(null,
                    "Konfiqurasiya faylı yoxdur.\nXəta mesajı = " + ex.getMessage(),
                    "Xəta", JOptionPane.ERROR_MESSAGE);
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null,
                    "Fayldan oxuma xətası baş verdi.\nXəta mesajı = " + ex.getMessage(),
                    "Xəta", JOptionPane.ERROR_MESSAGE);
        }

        setContentPane(desktop);
        ImagePanel panel = new ImagePanel(new ImageIcon("src\\dynamicdiscountsystem\\resources\\Discount-tags.jpg").getImage());
        getContentPane().add(panel);
        panel.setVisible(true);

    }//GEN-LAST:event_formWindowActivated

    private void individualDiscountMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_individualDiscountMenuItemActionPerformed

        Discount1Frame frame = new Discount1Frame();
        frame.setClosable(true);
        frame.setLocation(200, 200);
        desktop.add(frame);
        frame.setVisible(true);
    }//GEN-LAST:event_individualDiscountMenuItemActionPerformed

    private void sumDiscountMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sumDiscountMenuItemActionPerformed

        Discount2Frame frame = new Discount2Frame();
        frame.setClosable(true);
        frame.setLocation(200, 200);
        desktop.add(frame);
        frame.setVisible(true);

    }//GEN-LAST:event_sumDiscountMenuItemActionPerformed

    private void numberDiscountMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numberDiscountMenuItemActionPerformed

        Discount3Frame frame = new Discount3Frame();
        frame.setClosable(true);
        frame.setLocation(200, 200);
        desktop.add(frame);
        frame.setVisible(true);
    }//GEN-LAST:event_numberDiscountMenuItemActionPerformed

    private void discountApplicationMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_discountApplicationMenuItemActionPerformed
        DiscountApplication frame = new DiscountApplication();
        frame.setClosable(true);
        frame.setFocusable(true);
        frame.setMaximizable(true);
        frame.setIconifiable(true);
        desktop.add(frame);
        desktop.getDesktopManager().maximizeFrame(frame);
        frame.setVisible(true);
    }//GEN-LAST:event_discountApplicationMenuItemActionPerformed

    private void productSaleMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_productSaleMenuItemActionPerformed

        SellingFrame frame = new SellingFrame();
        frame.setClosable(true);
        frame.setFocusable(true);
        frame.setMaximizable(true);
        frame.setIconifiable(true);
        desktop.add(frame);
        desktop.getDesktopManager().maximizeFrame(frame);
        frame.setVisible(true);

    }//GEN-LAST:event_productSaleMenuItemActionPerformed

    private void usersDefinitionMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usersDefinitionMenuItemActionPerformed

        NewUserInputFrame frame = new NewUserInputFrame();
        //frame.setBounds(0, 0, this.getWidth(), this.getHeight());
        frame.setClosable(true);
        frame.setFocusable(true);
        frame.setMaximizable(true);
        frame.setIconifiable(true);
        desktop.add(frame);
        desktop.getDesktopManager().maximizeFrame(frame);
        frame.setVisible(true);
    }//GEN-LAST:event_usersDefinitionMenuItemActionPerformed

    private void closeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeMenuItemActionPerformed

        if (desktop.getSelectedFrame() != null) {
            desktop.getSelectedFrame().dispose();
        } else {
            JOptionPane.showMessageDialog(this, "Açıq olan hər hansı pəncərə yoxdur.");
        }
    }//GEN-LAST:event_closeMenuItemActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed

        AboutFrame frame = new AboutFrame();
        frame.setClosable(true);
        frame.setLocation(200, 150);
        desktop.add(frame);
        frame.setVisible(true);

    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void ReportMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReportMenuItemActionPerformed

        ReportFrame frame = new ReportFrame();
        frame.setClosable(true);
        frame.setFocusable(true);
        frame.setMaximizable(true);
        frame.setIconifiable(true);
        desktop.add(frame);
        desktop.getDesktopManager().maximizeFrame(frame);
        frame.setVisible(true);
    }//GEN-LAST:event_ReportMenuItemActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem ReportMenuItem;
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenuItem closeMenuItem;
    private javax.swing.JMenu definitionMenu;
    private javax.swing.JMenuItem discountApplicationMenuItem;
    private javax.swing.JMenu discountFormsMenu;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JMenuItem individualDiscountMenuItem;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem numberDiscountMenuItem;
    private javax.swing.JMenu operationMenu;
    private javax.swing.JMenuItem productInputMenuItem;
    private javax.swing.JMenuItem productSaleMenuItem;
    private javax.swing.JMenuItem sumDiscountMenuItem;
    private javax.swing.JMenuItem usersDefinitionMenuItem;
    // End of variables declaration//GEN-END:variables
}
